home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Panel;
- import symantec.itools.db.pro.ProjBinder;
- import symantec.itools.db.pro.ProjLink;
- import symantec.itools.db.pro.RelationView;
- import symjava.sql.SQLException;
-
- public class PercentControl extends Panel implements ProjLink {
- ProjBinder m_ProjBinder1;
- ProjBinder m_ProjBinder2;
- public boolean m_bshowAsPcnt = true;
- public boolean m_bshowNumbers = true;
- private float m_Used;
- private float m_Limit = 1.0F;
- private String m_Column1;
- private String m_Column2;
- private boolean bfirstPass = true;
- private int m_treatBlankAs;
- private boolean m_DynamicUpdate = false;
-
- public void setShowAsPercent(boolean percent) {
- this.m_bshowAsPcnt = percent;
- }
-
- public void setShowNumbers(boolean numbers) {
- this.m_bshowNumbers = numbers;
- }
-
- public void setLimit(int limit) {
- this.m_Limit = (float)limit;
- }
-
- public void setAmountUsed(int used) {
- this.m_Used = (float)used;
- }
-
- public void setBinding(RelationView relView, String column1, String column2) {
- int projNumber = 0;
- if (column1 != null) {
- try {
- this.m_Column1 = new String(column1);
- projNumber = relView.findProjByName(this.m_Column1);
- relView.bindProj(projNumber, this);
- } catch (SQLException Ex) {
- System.out.println("SQLException from PercentControl.setBinding: " + ((Throwable)Ex).getMessage());
- }
- }
-
- if (column2 != null) {
- try {
- this.m_Column2 = new String(column2);
- projNumber = relView.findProjByName(this.m_Column2);
- relView.bindProj(projNumber, this);
- } catch (SQLException Ex) {
- System.out.println("SQLException from PercentControl.setBinding: " + ((Throwable)Ex).getMessage());
- }
- }
- }
-
- public void init(ProjBinder binder) {
- if (this.bfirstPass) {
- this.m_ProjBinder2 = binder;
- this.bfirstPass = false;
- } else {
- this.m_ProjBinder1 = binder;
- }
- }
-
- public void notifyDataChange(ProjBinder binder) {
- try {
- if (binder.equals(this.m_ProjBinder1)) {
- this.m_Limit = binder.getFloat();
- } else {
- this.m_Used = binder.getFloat();
- }
- } catch (SQLException e) {
- System.out.println(((Throwable)e).getMessage());
- }
-
- ((Component)this).repaint();
- }
-
- public boolean notifySetData(ProjBinder binder) throws SQLException {
- return true;
- }
-
- public void setTreatBlankAs(String blank) {
- if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
- this.m_treatBlankAs = 0;
- } else if ((new String(blank)).toUpperCase().equals("NULL")) {
- this.m_treatBlankAs = 1;
- } else {
- if ((new String(blank)).toUpperCase().equals("EMPTY")) {
- this.m_treatBlankAs = 2;
- }
-
- }
- }
-
- public void setDynamicUpdate(boolean update) {
- this.m_DynamicUpdate = update;
- }
-
- public void paint(Graphics g) {
- float percentage = this.m_Used / this.m_Limit;
- g.setColor(Color.black);
- Dimension dim = ((Component)this).size();
- int w = dim.width;
- int h = dim.height;
- int intRectW = (int)((double)w * 0.96);
- int intRectH = (int)((double)h * 0.9);
- g.drawRect(0, 0, intRectW, intRectH);
- int barH = (int)((double)intRectH * 0.28);
- int barY = (int)((double)intRectH * 0.28);
- int totalBarLength = (int)((double)intRectW * 0.8);
- float position = (float)totalBarLength * percentage;
- int BarBoundary = (intRectW - totalBarLength) / 2;
- g.drawLine((int)((double)intRectW * 0.1), (int)((double)intRectH * 0.22), (int)((double)intRectW * 0.1), (int)((double)intRectH * 0.67));
- g.drawLine((int)((double)intRectW * 0.9), (int)((double)intRectH * 0.22), (int)((double)intRectW * 0.9), (int)((double)intRectH * 0.67));
- if (this.m_Used > this.m_Limit) {
- g.fillRect(BarBoundary, barY, totalBarLength, barH);
- g.setColor(Color.red);
- if (position - (float)totalBarLength > (float)totalBarLength) {
- position = (float)(totalBarLength * 2);
- }
-
- g.fillRect(BarBoundary, barY, (int)position - totalBarLength, barH);
- g.setColor(Color.black);
- if (h > 24 && this.m_bshowNumbers) {
- g.drawString((new Float(this.m_Limit)).toString(), (int)((double)intRectW * 0.072), (int)((double)intRectH * 0.9400000000000001));
- if (this.m_bshowAsPcnt) {
- g.drawString((new Integer((new Float(100.0F * percentage)).intValue())).toString() + "%", (int)((double)((float)BarBoundary + (position - (float)totalBarLength)) * 0.9400000000000001), (int)((double)intRectH * 0.9400000000000001));
- return;
- }
-
- g.drawString((new Float(this.m_Used)).toString(), (int)((double)((float)BarBoundary + (position - (float)totalBarLength)) * 0.9400000000000001), (int)((double)intRectH * 0.9400000000000001));
- return;
- }
- } else {
- g.setColor(Color.red);
- g.fillRect(BarBoundary, barY, totalBarLength, barH);
- g.setColor(Color.green);
- g.fillRect(BarBoundary, barY, (int)position, barH);
- g.setColor(Color.black);
- if (h > 24 && this.m_bshowNumbers) {
- g.drawString("0", (int)((double)intRectW * 0.08800000000000001), (int)((double)intRectH * 0.9400000000000001));
- g.drawString((new Float(this.m_Limit)).toString(), (int)((double)intRectW * 0.86), (int)((double)intRectH * 0.9400000000000001));
- if (this.m_Used != this.m_Limit && this.m_Used != 0.0F && h > 24) {
- if (this.m_bshowAsPcnt) {
- g.drawString((new Integer((new Float(100.0F * percentage)).intValue())).toString() + "%", (int)((double)((float)BarBoundary + position) * 0.9400000000000001), (int)((double)intRectH * 0.9400000000000001));
- return;
- }
-
- g.drawString((new Float(this.m_Used)).toString(), (int)((double)((float)BarBoundary + position) * 0.9400000000000001), (int)((double)intRectH * 0.9400000000000001));
- }
- }
- }
-
- }
- }
-